package view;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPanel;

import controller.Controller;

import model.Switch;

/**
 * Switch megfejelnítéséért felelős osztály
 * JPanel és MouseListener leszármazás és implementálás a kattinthatóságért
 * @author radioactivebee
 *
 */
public class SwitchView extends JPanel implements Paintable, MouseListener, ModelProvider {

	private static final long serialVersionUID = 1L;
	private int x;
	private int y;
	private Switch sw;
	public OutputView outputView;
	
	public SwitchView(int x, int y, Switch _sw) {
		super();
		this.x = x;
		this.y = y;		
		this.sw = _sw;
		this.outputView = new OutputView(x+25, y+25, sw.getOutput(), sw);
		
		setBounds(x, y, 40, 40);
		addMouseListener(this);
	}
	@Override
	public void mouseClicked(MouseEvent e){
		if(Controller.verbose){
			System.out.println("switchview mouse listener invoked");
		}
		Controller.getInstance().switchClicked(this);
		Controller.getInstance().outputClicked(outputView);
		Controller.getInstance().blockClicked(this);
		
	} 
	
	@Override
	public void paint(Graphics g) {
		g.setColor(Color.LIGHT_GRAY);
		g.fillRect(x, y, 40, 40);	
		
		g.setColor(Color.BLACK);
		g.drawRect(x, y, 40, 40);
		
		if(sw.getOutput().getState().equals(false)){
			g.setColor(Color.WHITE);			
		} else {
			g.setColor(Color.RED);		
		}		
		if(OutputView.darken){
			g.setColor(g.getColor().darker());
		}
		g.fillOval(x+5, y+5, 30, 30);
		
		g.setColor(Color.BLACK);
		g.drawOval(x+5, y+5, 30, 30);
	}
	
	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}
	
	public Switch getModel(){
		return sw;
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
	}

	@Override
	public void mousePressed(MouseEvent arg0) {	
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
	}

}
